﻿Public Partial Class UserChangePasswordQuestion
    Inherits BaseUserControl

    Public ReadOnly Property RequestedUsername() As String
        Get
            If Request.QueryString("username") IsNot Nothing Then
                Return Request.QueryString("username").ToString
            Else
                Return ""
            End If
        End Get
    End Property

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Public Overrides Sub Rebind()

    End Sub

    Protected Sub btnChangePasswordQuestion_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChangePasswordQuestion.Click

        If txtCurrentPassword.Text.Trim.Length = 0 Then
            Me.Prompt("Please enter Password!", UserControlPromptTypes.Alert)
            Exit Sub
        End If

        If txtPasswordQuestion.Text.Trim.Length = 0 Then
            Me.Prompt("Please enter Password Question!", UserControlPromptTypes.Alert)
            Exit Sub
        End If

        If txtPasswordAnswer.Text.Trim.Length = 0 Then
            Me.Prompt("Please enter Password Answer!", UserControlPromptTypes.Alert)
            Exit Sub
        End If

        Try

            Dim membershipUser As MembershipUser = Membership.GetUser(Me.RequestedUsername)
            Dim result As Boolean

            result = membershipUser.ChangePasswordQuestionAndAnswer(txtCurrentPassword.Text, txtPasswordQuestion.Text, txtPasswordAnswer.Text)

            If result Then
                Me.Prompt("Password Question and Answer has beedn changed successfuly!", UserControlPromptTypes.Successful)
            Else
                Me.Prompt("The password is not correct!", UserControlPromptTypes.Alert)
            End If

        Catch ex As Exception

            Me.RaiseError(ex)

        End Try

    End Sub

End Class